home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Char.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  7.4 KB  |  179 lines  |  [TEXT/Moml]

  1. (* Char -- SML Basis Library *)
  2.  
  3. type char = char
  4.  
  5. val minChar : char
  6. val maxChar : char
  7. val maxOrd  : int       
  8.  
  9. val chr     : int  -> char         (* may raise Chr *)
  10. val ord     : char -> int
  11. val succ    : char -> char         (* may raise Chr *)
  12. val pred    : char -> char         (* may raise Chr *)
  13.  
  14. val isLower     : char -> bool   (* contains "abcdefghijklmnopqrstuvwxyz"  *)
  15. val isUpper     : char -> bool   (* contains "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  *)
  16. val isDigit     : char -> bool   (* contains "0123456789"                  *)
  17. val isAlpha     : char -> bool   (* isUpper orelse isLower                 *)
  18. val isHexDigit  : char -> bool   (* isDigit orelse contains "abcdefABCDEF" *)
  19. val isAlphaNum  : char -> bool   (* isAlpha orelse isDigit                 *)
  20. val isPrint     : char -> bool   (* any printable character (incl. #" ")   *)
  21. val isSpace     : char -> bool   (* contains " \t\r\n\v\f"                 *)
  22. val isPunct     : char -> bool   (* printable, not space or alphanumeric   *) 
  23. val isGraph     : char -> bool   (* (not isSpace) andalso isPrint          *)
  24. val isAscii     : char -> bool   (* ord c < 128                            *)
  25. val isCntrl     : char -> bool   (* control character                      *)
  26.  
  27. val toLower     : char -> char
  28. val toUpper     : char -> char
  29.  
  30. val fromString  : string -> char option       (* ML escape sequences *)
  31. val toString    : char -> string              (* ML escape sequences *)
  32.  
  33. val fromCString : string -> char option       (* C escape sequences  *)
  34. val toCString   : char -> string              (* C escape sequences  *)
  35.  
  36. val contains    : string -> char -> bool
  37. val notContains : string -> char -> bool
  38.  
  39. val <  : char * char -> bool
  40. val <= : char * char -> bool
  41. val >  : char * char -> bool
  42. val >= : char * char -> bool
  43. val compare : char * char -> order
  44.  
  45. (* 
  46.    [char] is the type of characters.  
  47.  
  48.    [minChar] is the least character in the ordering <.
  49.  
  50.    [maxChar] is the greatest character in the ordering <.
  51.  
  52.    [maxOrd] is the greatest character code; equals ord(maxChar).
  53.  
  54.    [chr i] returns the character whose code is i.  Raises Chr if
  55.    i<0 or i>maxOrd.
  56.  
  57.    [ord c] returns the code of character c.
  58.  
  59.    [succ c] returns the character immediately following c, or raises
  60.    Chr if c = maxChar.
  61.  
  62.    [pred c] returns the character immediately preceding c, or raises
  63.    Chr if c = minChar.
  64.  
  65.    [isLower c] returns true if c is a lowercase letter (a to z).
  66.  
  67.    [isUpper c] returns true if c is a uppercase letter (A to Z).
  68.  
  69.    [isDigit c] returns true if c is a decimal digit (0 to 9).
  70.  
  71.    [isAlpha c] returns true if c is a letter (lowercase or uppercase).
  72.  
  73.    [isHexDigit c] returns true if c is a hexadecimal digit (0 to 9 or 
  74.    a to f or A to F).
  75.  
  76.    [isAlphaNum c] returns true if c is alphanumeric (a letter or a
  77.    decimal digit).
  78.  
  79.    [isPrint c] returns true if c is a printable character (space or visible)
  80.  
  81.    [isSpace c] returns true if c is a whitespace character (blank, newline,
  82.    tab, vertical tab, new page).
  83.  
  84.    [isGraph c] returns true if c is a graphical character, that is,
  85.    it is printable and not a whitespace character.
  86.  
  87.    [isPunct c] returns true if c is a punctuation character, that is, 
  88.    graphical but not alphanumeric.
  89.  
  90.    [isCntrl c] returns true if c is a control character, that is, if
  91.    not (isPrint c).
  92.  
  93.    [isAscii c] returns true if 0 <= ord c <= 127.
  94.  
  95.    [toLower c] returns the lowercase letter corresponding to c,
  96.    if c is a letter (a to z or A to Z); otherwise returns c.
  97.  
  98.    [toUpper c] returns the uppercase letter corresponding to c,
  99.    if c is a letter (a to z or A to Z); otherwise returns c.
  100.  
  101.    [contains s c] returns true if character c occurs in the string s;
  102.    false otherwise.  The function, when applied to s, builds a table
  103.    and returns a function which uses table lookup to decide whether a
  104.    given character is in the string or not.  Hence it is relatively
  105.    expensive to compute  val p = contains s  but very fast to compute 
  106.    p(c) for any given character.
  107.  
  108.    [notContains s c] returns true if character c does not occur in the
  109.    string s; false otherwise.  Works by construction of a lookup table
  110.    in the same way as the above function.
  111.  
  112.    [fromString s] attempts to scan a character or ML escape sequence
  113.    from the string s.  Does not skip leading whitespace.  For
  114.    instance, fromString "\\065" equals #"A".
  115.  
  116.    [toString c] returns a string consisting of the character c, if c
  117.    is printable, else an ML escape sequence corresponding to c.  A
  118.    printable character is mapped to a one-character string; bell,
  119.    backspace, tab, newline, vertical tab, form feed, and carriage
  120.    return are mapped to the two-character strings "\\a", "\\b", "\\t",
  121.    "\\n", "\\v", "\\f", and "\\r"; other characters with code less
  122.    than 32 are mapped to three-character strings of the form "\\^Z",
  123.    and characters with codes 127 through 255 are mapped to
  124.    four-character strings of the form "\\ddd", where ddd are three decimal 
  125.    digits representing the character code.  For instance,
  126.              toString #"A"      equals "A" 
  127.              toString #"\\"     equals "\\\\" 
  128.              toString #"\""     equals "\\\"" 
  129.              toString (chr   0) equals "\\^@"
  130.              toString (chr   1) equals "\\^A"
  131.              toString (chr   6) equals "\\^F"
  132.              toString (chr   7) equals "\\a"
  133.              toString (chr   8) equals "\\b"
  134.              toString (chr   9) equals "\\t"
  135.              toString (chr  10) equals "\\n"
  136.              toString (chr  11) equals "\\v"
  137.              toString (chr  12) equals "\\f"
  138.              toString (chr  13) equals "\\r"
  139.              toString (chr  14) equals "\\^N"
  140.              toString (chr 127) equals "\\127"
  141.              toString (chr 128) equals "\\128"
  142.  
  143.    [fromCString s] attempts to scan a character or C escape sequence
  144.    from the string s.  Does not skip leading whitespace.  For
  145.    instance, fromString "\\065" equals #"A".
  146.  
  147.    [toCString c] returns a string consisting of the character c, if c
  148.    is printable, else an C escape sequence corresponding to c.  A
  149.    printable character is mapped to a one-character string; bell,
  150.    backspace, tab, newline, vertical tab, form feed, and carriage
  151.    return are mapped to the two-character strings "\\a", "\\b", "\\t",
  152.    "\\n", "\\v", "\\f", and "\\r"; other characters are mapped to 
  153.    four-character strings of the form "\\ooo", where ooo are three 
  154.    octal digits representing the character code.  For instance,
  155.              toString #"A"      equals "A" 
  156.              toString #"A"      equals "A" 
  157.              toString #"\\"     equals "\\\\" 
  158.              toString #"\""     equals "\\\"" 
  159.              toString (chr   0) equals "\\000"
  160.              toString (chr   1) equals "\\001"
  161.              toString (chr   6) equals "\\006"
  162.              toString (chr   7) equals "\\a"
  163.              toString (chr   8) equals "\\b"
  164.              toString (chr   9) equals "\\t"
  165.              toString (chr  10) equals "\\n"
  166.              toString (chr  11) equals "\\v"
  167.              toString (chr  12) equals "\\f"
  168.              toString (chr  13) equals "\\r"
  169.              toString (chr  14) equals "\\016"
  170.              toString (chr 127) equals "\\177"
  171.              toString (chr 128) equals "\\200"
  172.  
  173.    [<] compares character codes.  That is, c1 < c2 returns true 
  174.    if ord(c1) < ord(c2), and similarly for <=, >, >=.  
  175.  
  176.    [compare(c1, c2)] returns LESS, EQUAL, or GREATER, according as c1 is
  177.    precedes, equals, or follows c2 in the ordering Char.< .
  178. *)
  179.